home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -in_the_mag- / reader_requests / dice_v3.15 / lib / fd / write.c < prev   
C/C++ Source or Header  |  1999-01-26  |  756b  |  42 lines

  1.  
  2. /*
  3.  *  WRITE.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <clib/dos_protos.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <fcntl.h>
  14. #include <ioctl.h>
  15. #include <errno.h>
  16.  
  17. int
  18. write(fd, buf, bytes)
  19. int fd;
  20. const void *buf;
  21. unsigned int bytes;
  22. {
  23.     _IOFDS *d;
  24.     int n = -1;
  25.  
  26.     chkabort();
  27.     if (d = __getfh(fd)) {
  28.     if (d->fd_Flags & (O_WRONLY|O_RDWR|O_APPEND)) {
  29.         if (d->fd_Exec)
  30.         return((*d->fd_Exec)(d->fd_Fh, IOC_WRITE, buf, (void *)bytes));
  31.  
  32.         if (d->fd_Flags & O_APPEND)
  33.         Seek(d->fd_Fh, 0L, 1);
  34.         n = Write(d->fd_Fh, buf, bytes);
  35.     } else {
  36.         errno = ENOPERM;
  37.     }
  38.     }
  39.     return(n);
  40. }
  41.  
  42.